const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
var app = getApp()


Page({

  /**
   * 页面的初始数据
   */
  data: {
    zsid:'',
    zsdata:{},
    detail: {},
    page: 1,
    endFlag: false,
    loadingFlag: false,
    flag: 0,
    navbar_bgcolor: wx.getStorageSync('navbar_bgcolor'),
    activeCategoryId: 4,
    schoolId: 0,
    placeList: [],  //场地信息
    classTypeList: [], //班型信息
    coachList: [],  //教练信息,
    evalList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //console.log('vvvvvv'+JSON.stringify(options));
    if(typeof(options.id) == 'undefined'){
        //进行存储招生的ID
        wx.setStorageSync('zsid', options.scene);
        this.setData({//将招生的ID，进行赋值
          zsid:options.scene
        })
    }else{
      //进行存储招生的ID
      wx.setStorageSync('zsid', options.id);
      this.setData({//将招生的ID，进行赋值
        zsid:options.id
      })
    }
    
    //获取通过ID绑定的基本数据
    this.loadData()
  },
  tabClick: function (e) {
    this.setData({
      activeCategoryId: e.currentTarget.id
    });
  },
  loadData(){
    // console.log(this.data.zsid);
    var that = this
    util.request(api.mangerIdDataUrl,{id:this.data.zsid,key:api.key}).then(function(res){
      // console.log(JSON.stringify(res));
      if(res.errno == '0'){
        that.setData({
          zsdata:res.data,
          schoolId:res.data.school_id
        })
        that.getSchoolDetail();
      }else if(res.errno === 402){
        wx.showModal({
          title: '错误',
          content:'不被允许的请求',
          showCancel: false
        })
    }
    })
  },
  getSchoolDetail: function () {
    wx.showLoading({
      title: '加载中',
    });

    setTimeout(function () {
      wx.hideLoading()
    }, 2000);

    let that = this;
    util.request(api.SchoolDetailorModel, {
      id: that.data.schoolId
    }).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          detail: res.data.detail,
          placeList: res.data.placeList,
          classTypeList: res.data.classTypeList,
          coachList: res.data.coachList
        });
      }
      wx.hideLoading();
    });
  },
  tobm: function (e) {
    var hasLogin = wx.getStorageSync("app.globalData.hasLogin");
    if (!hasLogin) {
      wx.navigateTo({
        url: '/pages/auth/login/login',
      })
    }else{
      /**保存一下当前选择的驾校信息 */
      wx.setStorageSync("schoolId",this.data.schoolId);
      wx.setStorageSync("schoolName",this.data.detail.name);
      wx.navigateTo({
        url: '/pages/school/detail/ScModel?schoolId='+this.data.schoolId+'&schoolName='+this.data.detail.name,
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})